home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / NLS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  4KB  |  137 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 493 of 505
  3. From : Andres Cvitkovich                   2:310/36.9           28 Apr 93  22:59
  4. To   : Jon Leosson                         2:391/20.0
  5. Subj : Reading the country info
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Hi Jon,
  8.  
  9. Wednesday, April 14 1993, Jon Leosson wrote to All:
  10.  
  11.  JL> Does anybody know how one can read the country info which is set by
  12.  JL> COUNTRY.SYS in DOS 4.0 and 5.0?  Any help would be appreciated...
  13.  
  14. or DOS 6.0 or DOS 3.x or ...  ;-)
  15.  
  16. here we go:
  17.  
  18. ---------------------------------------------------------------}
  19. Unit NLS;
  20.  
  21. { NLS.PAS - National Language Support }
  22. { ─────────────────────────────────── }
  23. { (W)  Written 1992  by A. Cvitkovich }
  24.  
  25. INTERFACE
  26.  
  27. CONST
  28.       DATE_USA    = 0;
  29.       DATE_EUROPE = 1;
  30.       DATE_JAPAN  = 2;
  31.       TIME_12HOUR = 0;
  32.       TIME_24HOUR = 1;
  33.  
  34. TYPE
  35.       CountryInfo = Record
  36.         ciDateFormat    : Word;
  37.         ciCurrency      : Array [1..5] Of Char;
  38.         ciThousands     : Char;
  39.         ciASCIIZ_1      : Byte;
  40.         ciDecimal       : Char;
  41.         ciASCIIZ_2      : Byte;
  42.         ciDateSep       : Char;
  43.         ciASCIIZ_3      : Byte;
  44.         ciTimeSep       : Char;
  45.         ciASCIIZ_4      : Byte;
  46.         ciBitField      : Byte;
  47.         ciCurrencyPlaces: Byte;
  48.         ciTimeFormat    : Byte;
  49.         ciCaseMap       : Procedure;
  50.         ciDataSep       : Char;
  51.         ciASCIIZ_5      : Byte;
  52.         ciReserved      : Array [1..10] Of Byte
  53.       End;
  54.  
  55.       DateString = String [10];
  56.       TimeString = String [10];
  57.  
  58. VAR   Country       : CountryInfo;
  59.  
  60.  
  61. FUNCTION GetCountryInfo (Buf: Pointer): Boolean;
  62. FUNCTION DateStr: DateString;
  63. FUNCTION TimeStr: TimeString;
  64.  
  65.  
  66. IMPLEMENTATION
  67.  
  68. USES Dos;
  69.  
  70. FUNCTION GetCountryInfo (Buf: Pointer): Boolean; Assembler;
  71. Asm
  72.     mov  ax, 3800h
  73.     push ds
  74.     lds  dx, Buf
  75.     int  21h
  76.     mov  al, TRUE
  77.     jnc  @@1
  78.     xor  al, al
  79. @@1:
  80.     pop  ds
  81. End;
  82.  
  83. FUNCTION DateStr: DateString;
  84. VAR   Year, Month, Day, Weekday  : Word;
  85.       dd, mm                     : String[2];
  86.       yy                         : String[4];
  87. BEGIN
  88.   GetDate (Year, Month, Day, WeekDay);
  89.   Str (Day:2, dd);    If dd[1] = ' ' Then dd[1] := '0';
  90.   Str (Month:2, mm);  If mm[1] = ' ' Then mm[1] := '0';
  91.   Str (Year:4, yy);
  92.   Case Country.ciDateFormat Of
  93.     DATE_USA:    DateStr := mm + Country.ciDateSep + dd +
  94.                             Country.ciDateSep + yy;
  95.     DATE_EUROPE: DateStr := dd + Country.ciDateSep + mm +
  96.                             Country.ciDateSep + yy;
  97.     DATE_JAPAN:  DateStr := yy + Country.ciDateSep + mm +
  98.                             Country.ciDateSep + dd;
  99.     Else         DateStr := ''
  100.   End;
  101. END;
  102.  
  103.  
  104. FUNCTION TimeStr: TimeString;
  105. VAR   Hour, Min, Sec, Sec100  : Word;
  106.       hh, mm, ss              : String[2];
  107.       ampm                    : Char;
  108. BEGIN
  109.   GetTime (Hour, Min, Sec, Sec100);
  110.   Str (Min:2, mm);    If mm[1] = ' ' Then mm[1] := '0';
  111.   Str (Sec:2, ss);    If ss[1] = ' ' Then ss[1] := '0';
  112.   Case Country.ciTimeFormat Of
  113.     TIME_12HOUR: Begin
  114.                    If Hour < 12 Then ampm := 'a' Else ampm := 'p';
  115.                    Hour := Hour MOD 12;
  116.                    If Hour = 0 Then Hour := 12;  Str (Hour:2, hh);
  117.                    TimeStr := hh + Country.ciTimeSep + mm +
  118.                               Country.ciTimeSep + ss + ampm + 'm'
  119.                  End;
  120.     TIME_24HOUR: Begin
  121.                    Str (Hour:2, hh);
  122.                    TimeStr := hh + Country.ciTimeSep + mm +
  123.                               Country.ciTimeSep + ss
  124.                  End;
  125.     Else TimeStr := ''
  126.   End;
  127. END;
  128.  
  129.  
  130. BEGIN
  131.   If Not GetCountryInfo (@Country) Then Begin
  132.      Country.ciDateFormat := DATE_USA;
  133.      Country.ciDateSep := '-';
  134.      Country.ciTimeFormat := TIME_12HOUR;
  135.      Country.ciTimeSep := ':';
  136.   End;
  137. END.